import time
from zentao_pms.base.base_get import Tools


class login_tool(Tools):
    login_url = "http://192.168.0.125:7007/www/index.php?m=user&f=login&referer=L3d3dy8="
    username_ele = '[name="account"]'  # 用户名css定位
    password_ele = '[name="password"]'  # 密码css定位
    login_button_ele = '[id="submit"]'  # 登录按钮css定位
    login_success_ele = '[id="userMenu"] a'  # 登录成功后的断言

    def login_action(self, username, password):
        self.visit(self.login_url)
        self.by_css(self.username_ele).send_keys(username)
        time.sleep(1)
        self.by_css(self.password_ele).send_keys(password)
        time.sleep(1)
        self.by_css(self.login_button_ele).click()
        time.sleep(1)

    def get_success_msg(self):
        return self.by_css(self.login_success_ele).text